namespace SimpleWebServices.Web.Mvc
{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.Web.Mvc;
    using System.Web.Routing;
    using SimpleWebServices.Configuration;
    using SimpleWebServices.Models;
    using SimpleWebServices.Web.Routing;

    [InternalServerError]
    [Allow(Methods = "GET, HEAD, OPTIONS")]
    [CacheControl, ContentLanguage, ContentLocation, ContentMD5]
    public sealed class SubmissionController : Controller, IRegisterRoutes
    {
        public void Register(RouteCollection routes)
        {
            if (null == routes)
            {
                throw new ArgumentNullException("routes");
            }

            routes.Add(new SubmissionRoute());
        }

        [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "ASP.NET MVC requires the method to be an instance member.")]
        public ActionResult Process()
        {
            FormSubmission model = HttpContextFactory.Current.Request.Tokenized<FormSubmission>();

            return SubmissionConfiguration.Handler(model.Data["handler"]).Process(model);
        }
    }
}